package com.ls.kdlss.ui.Login;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gm.common.utils.ToastUtil;
import com.gm.lib.views.titlebar.AbTitleBar;
import com.ls.kdlss.R;
import com.ls.kdlss.entity.SetinfomationEntity;
import com.ls.kdlss.ui.home.DiZhiActivity;
import com.wx.android.common.util.ActivityUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/11/21.
 */

public class SetInfomationActivity extends AppCompatActivity implements View.OnClickListener {


    @Bind(R.id.title_bar)
    AbTitleBar titleBar;
    @Bind(R.id.btn_male)
    Button btnMale;
    @Bind(R.id.btn_female)
    Button btnFemale;
    @Bind(R.id.tv_city)
    TextView tvCity;
    @Bind(R.id.btn_xiaoxue)
    Button btnXiaoxue;
    @Bind(R.id.btn_chuzhong)
    Button btnChuzhong;
    @Bind(R.id.btn_gaozhong)
    Button btnGaozhong;
    @Bind(R.id.btn_yuwen)
    Button btnYuwen;
    @Bind(R.id.btn_shuxue)
    Button btnShuxue;
    @Bind(R.id.btn_yingyu)
    Button btnYingyu;
    @Bind(R.id.btn_shengwu)
    Button btnShengwu;
    @Bind(R.id.btn_zhengzhi)
    Button btnZhengzhi;
    @Bind(R.id.btn_lishi)
    Button btnLishi;
    @Bind(R.id.btn_dili)
    Button btnDili;
    @Bind(R.id.btn_wuli)
    Button btnWuli;
    @Bind(R.id.btn_huaxue)
    Button btnHuaxue;

    public String xiaoxue = "";
    public String chuzhong = "";
    public String gaozhong = "";
    public List<String> grade = new ArrayList<>();
    @Bind(R.id.ll_subjects)
    LinearLayout llSubjects;

    public static String address = "北京市";
    public static String addressid = "";
    public String subject = "语文";
    @Bind(R.id.ed_nickname)
    public EditText edNickname;
    @Bind(R.id.nic)
    TextView nic;
    private String sex = "女";

    public static void lanuch(Context context) {
        ActivityUtil.startActivity(context, SetInfomationActivity.class);
    }

    @Override
    protected void onResume() {
        super.onResume();
        tvCity.setText(address);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_information);
        ButterKnife.bind(this);
        init();

    }

    public void init() {
        titleBar.setTitleText("填写个人资料");
        titleBar.setRightButton("下一步", Color.rgb(249, 249, 249));
        titleBar.getRightButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                SetinfomationEntity setinfomationEntity = new SetinfomationEntity();
                setinfomationEntity.setNickname(edNickname.getText().toString());
                setinfomationEntity.setSex(sex);
                setinfomationEntity.setArea_id("");
                setinfomationEntity.setGread_id(grade);
                setinfomationEntity.setClass_id(subject);
                if (edNickname.getText().toString().equals("")) {
                    ToastUtil.show("姓名不能为空");
                    return;
                }
                if (grade.size() == 0) {
                    ToastUtil.show("年级不能为空");
                    return;
                }
                SetInfomationTwoActivity.lanuch(SetInfomationActivity.this);

            }
        });
        btnYuwen.setBackgroundColor(Color.rgb(3, 178, 235));
        btnFemale.setBackgroundColor(Color.rgb(251, 105, 143));

    }


    @Override
    @OnClick({R.id.title_bar, R.id.btn_male, R.id.btn_female, R.id.tv_city, R.id.btn_xiaoxue, R.id.btn_chuzhong, R.id.btn_gaozhong, R.id.btn_yuwen, R.id.btn_shuxue, R.id.btn_yingyu, R.id.btn_shengwu, R.id.btn_zhengzhi, R.id.btn_lishi, R.id.btn_dili, R.id.btn_wuli, R.id.btn_huaxue, R.id.ll_subjects})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_male:
                btnMale.setBackgroundColor(Color.rgb(3, 178, 235));
                btnFemale.setBackgroundColor(Color.rgb(255, 255, 255));
                break;
            case R.id.btn_female:
                btnFemale.setBackgroundColor(Color.rgb(251, 105, 143));
                btnMale.setBackgroundColor(Color.rgb(255, 255, 255));
                sex = "女";
                break;
            case R.id.tv_city:
                DiZhiActivity.launch(SetInfomationActivity.this);
                break;
            /**年级**/
            case R.id.btn_xiaoxue:
                if (xiaoxue.equals("")) {
                    btnXiaoxue.setBackgroundColor(Color.rgb(3, 178, 235));


                    xiaoxue = "小学";
                    grade.add("小学");
                } else {
                    btnXiaoxue.setBackgroundColor(Color.rgb(255, 255, 255));
                    xiaoxue = "";

                    for (int i = 0; i < grade.size(); i++) {
                        if (grade.get(i).equals("小学")) {
                            grade.remove(i);
                        }
                    }
                }
                break;

            case R.id.btn_chuzhong:
                if (chuzhong.equals("")) {
                    btnChuzhong.setBackgroundColor(Color.rgb(3, 178, 235));
                    chuzhong = "初中";
                    grade.add("初中");
                } else {
                    btnChuzhong.setBackgroundColor(Color.rgb(255, 255, 255));
                    chuzhong = "";
                    for (int i = 0; i < grade.size(); i++) {
                        if (grade.get(i).equals("初中")) {
                            grade.remove(i);
                        }
                    }
                }
                break;
            case R.id.btn_gaozhong:
                if (gaozhong.equals("")) {
                    btnGaozhong.setBackgroundColor(Color.rgb(3, 178, 235));


                    gaozhong = "高中";
                    grade.add("高中");
                } else {
                    btnGaozhong.setBackgroundColor(Color.rgb(255, 255, 255));
                    gaozhong = "";
                    for (int i = 0; i < grade.size(); i++) {
                        if (grade.get(i).equals("初中")) {
                            grade.remove(i);
                        }
                    }
                }
                break;
            /**************************************************/
            case R.id.btn_yuwen:
                isClick(btnYuwen);
                break;
            case R.id.btn_shuxue:
                isClick(btnShuxue);
                break;
            case R.id.btn_yingyu:
                isClick(btnYingyu);
                break;
            case R.id.btn_shengwu:
                isClick(btnShengwu);
                break;
            case R.id.btn_zhengzhi:
                isClick(btnZhengzhi);
                break;
            case R.id.btn_lishi:
                isClick(btnLishi);
                break;
            case R.id.btn_dili:
                isClick(btnDili);
                break;
            case R.id.btn_wuli:
                isClick(btnWuli);
                break;
            case R.id.btn_huaxue:
                isClick(btnHuaxue);
                break;
        }
    }


    public void isClick(Button button) {
        Button[] buttons = new Button[]{btnYuwen, btnShuxue, btnYingyu, btnShengwu, btnZhengzhi, btnLishi, btnDili, btnWuli, btnHuaxue};
        for (int i = 0; i < buttons.length; i++) {
            buttons[i].setBackgroundColor(Color.rgb(255, 255, 255));
        }
        button.setBackgroundColor(Color.rgb(3, 178, 235));
        subject = button.getText().toString();

    }


}
